@isTest 
private class ContractWebServiceTest{


    static testMethod void testMethod1() {
        

        //创建经理
        Id ldcProfile = [Select Id From Profile Where Name ='系统管理员' or Name='System Administrator'].Id;
       
                     
        Account a = TestUtils.createAccount();
        a.Level__c = '一级医院';
        a.AccountNumber = '01';


        //业务机会1
        Opportunity opp = TestUtils.createOpportunity();
        opp.AccountId = a.Id;
        opp.Corpcode__c = 'MKSY';
        insert opp; 


        a.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('Maccura', 'Account');
        insert a;
         ProductStructure__c ps = new ProductStructure__c();
        ps.Classify3__c = '试剂';
        insert ps;



        

        //创建产品
        Product__c p = new Product__c();
        p.NCCode__c = '11111';
        p.ProductStructure__c = ps.Id;


        insert p;
        //创建合同产品
        ContractReagentInformation__c cr = new ContractReagentInformation__c();
        cr.Price__c = 1;
        cr.ReagentProducts__c = p.Id;
        cr.Opportunity__c = opp.Id;
        insert cr  ;
       // cp.Number__c = 10;
        ContractWebService.postOppToNC(opp.Id);
    }
    /*static testMethod void testMethod1(){
   
        //创建经理
        Id ldcProfile = [Select Id From Profile Where Name ='系统管理员' or Name='System Administrator'].Id;
       
                     
        Account a = TestUtils.createAccount();
        a.Level__c = '一级医院';
        a.AccountNumber = '01';

        a.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('Maccura', 'Account');
        insert a;
         ProductStructure__c ps = new ProductStructure__c();
        ps.Classify3__c = '试剂';
        insert ps;
        //创建合同
        Contract__c c = new Contract__c();
        c.Corpcode__c = 'MKSY';
        c.Status__c = '草稿';
        c.Vsalestrucode__c = '05';
        c.Maccura__c = a.Id;


        insert c ;
        //创建产品
        Product__c p = new Product__c();
        p.NCCode__c = '11111';
         p.ProductStructure__c = ps.Id;

        insert p;
        //创建合同产品
        ContractProduct__c cp = new ContractProduct__c();
        cp.Contract__c = c.Id;
        cp.SalesPrice__c = 10.0;
        cp.Product__c = p.Id;
        cp.Only__c = 'cp2';
    	insert cp ;
       // cp.Number__c = 10;
        ContractWebService.postQuote(c.Id, '1', '1');
        System.debug('发送OA');
        ContractWebService.postOA(c.Id);

    }*/

/*
    static testMethod void testMethod2(){


       
             //客户1
            Account acc = TestUtils.createAccount();
            acc.Level__c = '三级甲等';
            insert acc;     

            //业务机会1
            Opportunity opp = TestUtils.createOpportunity();
            opp.AccountId = acc.Id;
            insert opp;

          
            //报价2
            Quote qt2 = new Quote(Name = '试剂报价',Type__c = '试剂报价',OpportunityId = opp.Id);
            insert qt2;

            Id rt = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c');
            //产品1    
            Product__c p1 = TestUtils.createProduct();        
            p1.Category1__c = '微生物'; 
            p1.Purpose__c = '仪器报价用';
            p1.RecordTypeId = rt;
       
            Product__c p2 = TestUtils.createProduct();
            p2.Name = 'Test1';
             p2.Purpose__c = '仪器报价用';

            p2.Category1__c = '免疫';   
            p2.RecordTypeId = rt;
            insert new Product__c[] {p1, p2};
            //报价产品1
            QuoteProduct__c qp2 = new QuoteProduct__c(Name = '测试报价产品2',SalesPrice__c= 1,Product__c = p2.Id,Quote__c = qt2.Id);
            insert qp2;
             ContractWebService.postQuoteProduct(qt2.Id);

             AdjustPriceHandler.adjustQuoteToPriceList(qt2.Id);


        

    }
    */
    /*
    static testMethod void testMethod3(){
   
        //客户1
        Account acc = TestUtils.createAccount();
        acc.Level__c = '三级甲等';
        insert acc;
        
        //业务机会1
        Opportunity opp = TestUtils.createOpportunity();
        opp.AccountId = acc.Id;
        insert opp;
        system.debug(opp+'=========================');
        System.Test.startTest();
        //报价1
        Quote qt = new Quote(Name = '测试报价', OpportunityId = opp.Id);
        insert qt;
        Id rt = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c');

        //产品1
        Product__c p1 = TestUtils.createProduct();    
        p1.Category1__c = '微生物';
        p1.Category0__c = '仪器';
        p1.RecordTypeId = rt;

        Product__c p2 = TestUtils.createProduct();
        p2.Name = 'Test1';
        p2.Category0__c = '试剂';
        p2.Category1__c = '免疫';  
        p2.RecordTypeId = rt; 
        Product__c p3 = TestUtils.createProduct(); 
        p3.Name = 'Test2';   
        p3.Category1__c = '生化';
        p3.Category0__c = '仪器';  
        p2.RecordTypeId = rt; 
        insert new Product__c[] {p1, p2, p3};

        //报价产品
      //  QuoteProduct__c qp1 = new QuoteProduct__c(Product__c = p3.Id, Quote__c = qt.Id);
        //insert qp1;

        //测算信息1
        Measure_Calculate__c mc = new Measure_Calculate__c(Opportunity__c = opp.Id);
        insert mc;

        //测算信息产品1
        Measure_Calculate_Product__c mcp1 = new Measure_Calculate_Product__c(Product__c = p1.Id, Measure_Calculate__c = mc.Id);
        Measure_Calculate_Product__c mcp2 = new Measure_Calculate_Product__c(Product__c = p2.Id, Measure_Calculate__c = mc.Id);
        insert new Measure_Calculate_Product__c[] {mcp1, mcp2};

        ContractWebService.postMeasureProduct(mc.Id);

        AdjustPriceHandler.adjustMeasuerToPriceList(mc.Id);


    }

    */
    static testMethod void testMethod4(){
         Id ldcProfile1 = [Select Id,Name From Profile Where Name like '%工程部%' limit 1 ].Id;
        User u1 = new User( Alias = 'samLdc1', 
                         Email = 'ldc@test.com.maike',
                         Emailencodingkey = 'UTF-8', 
                         Lastname = '用户1', 
                         Languagelocalekey = 'en_US',
                         Localesidkey = 'en_US', 
                         Profileid = ldcProfile1, 
                         Country = 'United States',
                         companyName = 'Y-MKSY',
                         IsActive = true,
                         ManagerId= UserInfo.getUserId(),

                         FederationIdentifier = '3451',
                         SubCompany__c='四川省迈克实业有限公司',
                         UserDepartment__c='客户服务中心(工程部)',
                         Timezonesidkey = 'America/Los_Angeles', 
                         Province__c ='四川省',
                         EmployeeNumber = '123451',
                         Username = 'Matldc1@test.com.maike');
        insert u1;
        System.runAs(u1){
            Account acc = TestUtils.createAccount();
            acc.Level__c = '一级医院';
            insert acc;
            
            ProductStructure__c ps = new ProductStructure__c();
            ps.Classify3__c = '试剂';
            insert ps;
            Product__c p1 = TestUtils.createProduct();
            p1.Category0__c = '试剂';
            p1.ProductStructure__c = ps.Id;
            p1.PriceCompany__c = 'MKSY';
            p1.NCCode__c = '000001';
            p1.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c');
            
            Product__c p2 = TestUtils.createProduct();
            p2.Category0__c = '试剂';
            p2.ProductStructure__c = ps.Id;
            p2.PriceCompany__c = 'MKSY';
            p2.NCCode__c = '000002';
            p2.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c');
            insert new Product__c[] {p1, p2};

            AdjustPrice__c ap = new AdjustPrice__c();
            ap.Account__c = acc.Id;
            ap.SalesCode__c = '05';
            insert ap;
            Product__c testp = [select Id,FirstCode__c,SealCompany__c,RecordType.DeveloperName from Product__c where Id =:p1.Id ];
            system.debug('ContractWebService==>'+testp.SealCompany__c+' '+testp.FirstCode__c+' '+testp.RecordType.DeveloperName);
            system.debug('ContractWebService==>'+[select Id,SubCompany__c,companyName from User where Id=:UserInfo.getUserId() ]);
            AdjustPriceProduct__c app = new AdjustPriceProduct__c();
            app.AdjustPrice__c = ap.Id;
            app.Product__c = p1.Id;
            app.OriginalPrice__c = 1;
            app.AdjustSalesPrice__c = 2;
            insert app;

            ContractWebService.postAdprice(ap.Id);
            AdjustPriceHandler.adjustPriceToPriceList(ap.Id);
        }

    }
    
        static testMethod void testMethod5(){

                  //客户1
            Account acc = TestUtils.createAccount();
            acc.Level__c = '三级甲等';
            acc.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('DealerAbroad', 'Account');
            insert acc;     

            //业务机会1
            Opportunity opp = TestUtils.createOpportunity();
            opp.AccountId = acc.Id;
            opp.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('OverseaDearlerOpportunity', 'Opportunity');

            insert opp;

          
            //报价2
            Quote qt2 = new Quote(Name = '海外报价',OpportunityId = opp.Id);
            insert qt2;

            Id rt = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c');
            //产品1    
            Product__c p1 = TestUtils.createProduct();        
            p1.Category1__c = '微生物'; 
            p1.Purpose__c = '仪器报价用';
            p1.Category0__c = '仪器';  
            p1.RecordTypeId = rt;
       
            Product__c p2 = TestUtils.createProduct();
            p2.Name = 'Test1';
             p2.Purpose__c = '仪器报价用';

            p2.Category1__c = '免疫'; 
            p2.Category0__c = '仪器';  
            p2.RecordTypeId = rt;
            insert new Product__c[] {p1, p2};
            //报价产品1
            QuoteProduct__c qp1 = new QuoteProduct__c(Name = '测试报价产品2',CooperativePrice__c= 1,Product__c = p1.Id,Quote__c = qt2.Id);
            insert qp1;
            QuoteProduct__c qp2 = new QuoteProduct__c(Name = '测试报价产品2',CooperativePrice__c= 1,Product__c = p2.Id,Quote__c = qt2.Id);
            insert qp2;


            // String msg = ContractWebService.postOverseaQuote( qt2.Id  );
             // System.debug('ContractWebServiceTest==>'+msg);
            try {
                             AdjustPriceHandler.adjustAboardQuoteToPriceList(qt2.Id );

            }
            catch (Exception e) {
                
            }
            
            
        }

        static testMethod void testMethod6(){
        
            Account acc = TestUtils.createAccount();
            acc.Level__c = '一级医院';
            acc.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('DealerAbroad', 'Account');

            insert acc;
            
            ProductStructure__c ps = new ProductStructure__c();
            ps.Classify3__c = '试剂';
            insert ps;

            Product__c p1 = TestUtils.createProduct();
            p1.Category0__c = '试剂';
            p1.ProductStructure__c = ps.Id;
            p1.PriceCompany__c = 'MKSY';
            p1.NCCode__c = '000001';
            p1.RelatedProducts__c = '000002' ;
            p1.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c');
            
            Product__c p2 = TestUtils.createProduct();
            p2.Category0__c = '试剂';
            p2.ProductStructure__c = ps.Id;
            p2.PriceCompany__c = 'MKSY';
            p2.NCCode__c = '000002';
            p2.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c');
            insert new Product__c[] {p1, p2};

            AdjustPrice__c ap = new AdjustPrice__c();
            ap.Account__c = acc.Id;
            ap.SalesCode__c = '05';
            insert ap;

            AdjustPriceProduct__c app = new AdjustPriceProduct__c();
            app.AdjustPrice__c = ap.Id;
            app.Product__c = p1.Id;
            app.OriginalPrice__c = 1;
            app.AdjustSalesPrice__c = 2;
            app.PresentPrice__c = 1;
            insert app;

           // String msg = ContractWebService.postOverseaAdprice(ap.Id );
           // System.debug('ContractWebServiceTest==>'+msg);

            AdjustPriceHandler.adjustAboardPriceToPriceList(ap.Id );
        

    }


}